package com.lovo;

import java.util.Scanner;
import java.util.regex.Pattern;

public class AccountEnroll {

    public static Scanner scan = new Scanner(System.in);


    public static void main(String[] args) {
        System.out.println("欢迎注册朗沃公司学员账号");
        user();
    }

    public static void user() {
        System.out.println("输入用户名，要求6-20位字母、数字、下划线组成");

        while (true) {
            String use = scan.next();
            boolean b = use.matches("^[a-zA-Z0-9_]{6,20}?$");
            if (b) {
                password();
                break;
            } else {
                System.out.println("请按要求来写");
            }
        }
    }

    public static void password() {
        System.out.println("输入密码，要求(必须包含大小写字母和数字的组合，不能使用特殊字符，长度不少于6位）");
        while (true) {
            String pas = scan.next();
            boolean a = pas.matches("^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{6,}$");
            if (a) {
                System.out.println("请确认密码");
                String pas1 = scan.next();
                if (pas.equals(pas1)) {
                    System.out.println("请输入邮箱");
                    email();
                    break;
                } else {
                    System.out.println("请重新输入密码");

                }

            } else {
                System.out.println("请按照格式");
            }
        }

    }

    public static void email() {
        while (true) {
            String ema = scan.next();
            boolean a = ema.matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
            if (a) {
                System.out.println("注册成功");
                break;
            } else {
                System.out.println("格式不对，请重新输入");
            }
        }
    }
}
